/*
    api:"添加公司信息"
    name:"陈小洋"
    time：2021.1.24
* */
const Company = require('../../../control/Company/Company')
const tools = require('../../../tools/public');
/**
 * @api {post} /company/addCompany 1.添加公司信息
 * @apiGroup Company
 *
 * @apiParam {String} CompanyName 公司名字
 * @apiParam {String} CompanyIntroduce 公司介绍
 * @apiParam {String} CompanyLogo 公司logo
 * @apiParam {String} CompanyInImgs 公司环境照片
 * @apiParam {String} CompanyRegion 公司所在城市
 * @apiParam {String} CompanyRegionNumber 公司所在城市编码
 * @apiParam {String} CompanyAdress 公司详细地址
 * @apiParam {Number} CompanyPhone 公司电话
 * @apiParam {Number} CompanyRegisterTime 公司注册时间
 * @apiParam {Number} CompanyRegisterMoney 公司注册资金
 * @apiParam {String} CompanyLegalPerson 公司法人
 * @apiParam {String} CompanyScale 公司规模
 * @apiParam {String} CompanyFree 公司福利
 * @apiParam {String} SocialUnifiedCreditCode 统一社会信用代码
 * @apiParam {String} CompanyIndustry 公司行业
 *
 *
 * @apiParamExample {json} Request-Example
 *{
 *
 *}
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "code": 200,
 *   "msg": "该公司已存在！"
*   }
 */
module.exports = async function (req, res, next) {
    let {
            CompanyLogo,
            CompanyName,
            CompanyIntroduce,
            CompanyInImgs,
            CompanyRegion,
            CompanyRegionNumber,
            CompanyAdress,
            CompanyPhone,
            CompanyRegisterTime,
            CompanyRegisterMoney,
            CompanyLegalPerson,
            CompanyScale,
            CompanyFree,
            SocialUnifiedCreditCode,CompanyIndustry
        } = req.body,
        result = null;
    try {
        if (!CompanyLogo || !CompanyName || !CompanyIntroduce || !CompanyInImgs || !CompanyRegion || !CompanyRegionNumber ||
            !CompanyAdress || !CompanyPhone || !CompanyRegisterTime || !CompanyRegisterMoney || !CompanyLegalPerson ||
            !CompanyScale || !CompanyFree || !SocialUnifiedCreditCode || !CompanyIndustry) return res.send(tools.ReturnData(204, '参数错误,请认真阅读接口文档！'));

        result = await Company.Sel_quoteType('CompanyName',CompanyName);
        if (result.length > 0) {
            res.send(tools.ReturnData(200, '该公司已存在！'));
        } else { // 不存在注册新公司
            await Company.Add({
                CompanyLogo,
                CompanyName,
                CompanyIntroduce,
                CompanyInImgs,
                CompanyRegion,
                CompanyRegionNumber,
                CompanyAdress,
                CompanyPhone,
                CompanyRegisterTime:new Date(CompanyRegisterTime).getTime(),
                CompanyRegisterMoney,
                CompanyLegalPerson,
                CompanyScale,
                CompanyFree,
                SocialUnifiedCreditCode,
                CompanyIndustry
            });
            res.send(tools.ReturnData(200, '公司信息添加成功！'));
        }
    } catch (e) {
        console.log(e)
        return res.send(tools.ReturnData(500, '系统内部错误！'));
    }
};